from extension.wrapper.huakunipmi import parser


def ipmi_get_mc_info(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")

    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} mc info"
    return [{"cmdline": cmd.split(), "parser": parser.parse_colon_separated_data}]


def ipmi_get_fru_info(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")

    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} fru print"
    return [{"cmdline": cmd.split(), "parser": parser.parse_colon_separated_data}]


def ipmi_get_sdr_info(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")

    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} sdr list"
    return [{"cmdline": cmd.split(), "parser": parser.parse_colon_separated_data}]


def ipmi_set_dpu_power_status(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")
    status = params.get("status")

    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} chassis power {status}"
    return [{"cmdline": cmd.split(), "parser": parser.parser_raw_output}]


def ipmi_set_dpu_boot_dev(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")
    boot_dev = params.get("boot_dev")

    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} chassis bootparam set bootflag {boot_dev}"
    return [{"cmdline": cmd.split(), "parser": parser.parser_raw_output}]


def ipmi_get_dpu_boot_dev(self, params=None):
    """
    """
    ip = params.get("ip")
    user_name = params.get("user_name", "Administrator")
    pwd = params.get("pwd", "Admin@9000")
    cmd = f"ipmitool -I lanplus -U {user_name} -P {pwd} -H {ip} bootparam get 5"
    return [{"cmdline": cmd.split(), "parser": parser.parser_raw_output}]


def ipmi_set_chassis_power_status(self, options=None):
    """
    """
    cmd = f"ipmitool power {options}"
    return [{"cmdline": cmd.split(), "parser": parser.parser_raw_output}]
